package com.lms.util;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-05-13 07:25
 * @Description: ${Description}
 */
//@SuppressWarnings("all")
public class ObjectsDemo {
    public static void main(String[] args) {
        CopyOnWriteArrayList<Object> copy = new CopyOnWriteArrayList<>();
        ArrayList<Object> objects = new ArrayList<>();
        boolean a = copy.add("a");
        boolean b = copy.addIfAbsent(2);  //不存在则添加
        boolean b1 = copy.addIfAbsent(2);
        System.out.println(a);
        System.out.println(b);
        System.out.println(b1);
        Iterator<Object> iterator = copy.iterator();  //数组在迭代器的生命周期内永远不会改变
        boolean add = copy.add(3);
        iterator.forEachRemaining(System.out::println);//a,2



    }
}
